package com.huan;

import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;

//客户端

public class Test2_Client {
    public static void main(String[] args) throws IOException {
        InetAddress[] inetAddresses = InetAddress.getAllByName("www.baidu.com");
        if(inetAddresses!=null){
            for (InetAddress i:inetAddresses){
                //客户端创建套接字
                Socket client = new Socket(i,80);
                System.out.println("连接成功，"+client);
                //Socket[addr=www.baidu.com/153.3.238.102,port=80,localport=7899]
                //套接字[IP地址，协议端口号，本机端口号]（本机端口号是随机的）
                break;
            }
        }
        Socket client = new Socket("www.baidu.com",80);
        System.out.println("连接成功，"+client);
        Socket client1 = new Socket("153.3.238.110",80);
        System.out.println("连接成功，"+client1);
    }
}
